package test.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * 堆内存溢出测试
 * VM Args: -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
 * @author zzq
 * @datetime 2025-01-01 15:29
 *
 * java.lang.OutOfMemoryError: Java heap space
 * Dumping heap to java_pid20660.hprof ...
 * Heap dump file created [28153577 bytes in 0.099 secs]
 * Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
 */
public class HeapOOM {

	static class OOMObject {}

	public static void main(String[] args) {
		List<OOMObject> list = new ArrayList<OOMObject>();
		//int i=0;
		while (true) {
			//System.out.println(i++);
			list.add(new OOMObject());
		}
	}
}
